package com.dbuil.bleshoes.ui.activity;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.dbuil.bleshoes.R;
import com.dbuil.bleshoes.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CountAnimActivity extends BaseActivity {
    @BindView(R.id.tv_count)
    TextView tvCount;
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_top_title)
    TextView tvTopTitle;
    @BindView(R.id.tv_top_right)
    TextView tvTopRight;
    @BindView(R.id.img_top_right)
    ImageView imgTopRight;

    @Override
    public int getLayoutId() {
        return R.layout.activity_countanim;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);


        initAnim();


    }

    /*数字加载动画*/
    private void initAnim() {
        int count=280;
        ValueAnimator valueAnimator = ValueAnimator.ofInt(0, count);
        valueAnimator.setDuration(1500);
        //插值器-先加速后减速
        valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
        //插值器-超值
      //  valueAnimator.setInterpolator(new OvershootInterpolator());
        //插值器-减速
//        valueAnimator.setInterpolator(new DecelerateInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {

                int animatedValue = (int) valueAnimator.getAnimatedValue();

                tvCount.setText(animatedValue + "");

            }
        });
        valueAnimator.start();
    }

    @OnClick({R.id.tv_count, R.id.img_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_count:
                initAnim();
                break;
            case R.id.img_back:
                this.finish();
                break;
        }
    }


}
